using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum PropType
{
    Def,
    Hp,
    Atk
}

public class PropReward : MonoBehaviour
{
    public PropType rewardType = PropType.Def;

    public int value;

    public GameObject getBuff;

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            PlayerTank playerTank = other.GetComponent<PlayerTank>();

            switch (rewardType)
            {
                case PropType.Def:
                    playerTank.def += value;
                    break;
                case PropType.Hp:
                    playerTank.hp += value;
                    if (playerTank.hp > playerTank.maxHp)
                    {
                        playerTank.hp = playerTank.maxHp;
                    }

                    //更新血条
                    GamePanel.Instance.UpdateHP(playerTank.hp);
                    break;
                case PropType.Atk:
                    playerTank.atk += value;
                    break;
                default:
                    break;
            }

            GameObject buff = Instantiate(getBuff, this.transform.position, this.transform.rotation);
            AudioSource audioSource = buff.GetComponent<AudioSource>();
            audioSource.volume = GameDataManager.Instance.musicData.soundValue;
            audioSource.mute = !GameDataManager.Instance.musicData.isOpenSound;
            Destroy(gameObject);
        }
    }
}